package com.ftg.wymall.admin.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ftg.wymall.admin.dto.UserInfo;
import com.ftg.wymall.admin.entity.UmsAdmin;
import com.ftg.wymall.admin.service.IUmsAdminService;
import com.ftg.wymall.admin.vo.UmsAdminVo;
import com.ftg.wymall.comm.vo.CodeStatusEnum;
import com.ftg.wymall.comm.vo.RespMessUtil;
import com.ftg.wymall.config.ConstClass;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * <p>
 * 后台用户表 前端控制器
 * </p>
 *
 * @author kangjx
 * @since 2023-10-20
 */
@RestController
@Api(tags = "管理员模块")
@RequestMapping("/ums/admin/umsAdmin")
public class UmsAdminController {

    @Resource
    IUmsAdminService iUmsAdminService;

    /**
     * @requestbody 对应的调用者为  application/json 格式 以请求体传参
     * @requestparam 对应的 ?传递方式
     * @pathvarible  /{ss}/{sss}
     * @param userinfo
     * @return
     */
    @ApiOperation("后台_用户登陆功能")
    @PostMapping("/login")
    public RespMessUtil<UmsAdminVo> login(
            @RequestBody UserInfo userinfo
    ){
        return iUmsAdminService.login(userinfo);
    }


    @ApiOperation("个人中心修改个人信息功能")
    @PostMapping("/modifyUser")
    public RespMessUtil<Boolean> modifyUser(
       @RequestBody UmsAdmin user
    ){
        return iUmsAdminService.modifyUser(user);
    }


    @ApiOperation("头像功能处理")
    @PostMapping("/uploadAvatar/{id}")
    public RespMessUtil<JSONObject> uploadAvatar(
            @PathVariable("id")Long id,
            @ApiParam("avatarFile") @RequestParam("avatarFile") MultipartFile avatarFile
    ){
        return iUmsAdminService.uploadAvatar(id,avatarFile);
    }

    @Resource
    ConstClass constClass;

    @ApiOperation("nacso案例,配置中心")
    @GetMapping("/nacosconfig")
    public RespMessUtil<String> nacosConfig(){
        return RespMessUtil.build(CodeStatusEnum.SUCCESS,constClass.getTipUploadAvatarFail());
    }


}
